package com.savi.myapplication.fragment;

import android.graphics.Color;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;

import com.savi.myapplication.EFBGlobalData;
import com.savi.myapplication.FlyCardActivity;
import com.savi.myapplication.R;
import com.savi.myapplication.adapter.AddFlyCardPopupWindow;
import com.savi.myapplication.adapter.FlyTaskCardDataLeftAdatper;
import com.savi.myapplication.model.FlyCardInfo;
import com.yanzhenjie.recyclerview.OnItemMenuClickListener;
import com.yanzhenjie.recyclerview.SwipeMenu;
import com.yanzhenjie.recyclerview.SwipeMenuBridge;
import com.yanzhenjie.recyclerview.SwipeMenuCreator;
import com.yanzhenjie.recyclerview.SwipeMenuItem;
import com.yanzhenjie.recyclerview.SwipeRecyclerView;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link FlyTimeFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class FlyTimeFragment extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    private View rootView;
    private ImageButton m_imgAddTaskCard;
    private AddFlyCardPopupWindow addFlyCardPopupWindow;
    private FlyCardActivity activity;

    //卡片基本数据列表
    private SwipeRecyclerView recyChartBase;
    private FlyTaskCardDataLeftAdatper flyTaskCardDataLeftAdatper;
    //飞行卡片左侧信息列表
    private List<FlyCardInfo> m_flyCardInfoList;
    //右侧添加卡片基本信息的个数
    private List<Integer> numberList;
    //无卡片信息
    private TextView m_tvNoCardInfo;



    private EFBGlobalData g_App;

    public FlyTimeFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment FlyTimeFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static FlyTimeFragment newInstance(String param1, String param2) {
        FlyTimeFragment fragment = new FlyTimeFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        rootView = inflater.inflate(R.layout.fragment_fly_time, container, false);
        activity = (FlyCardActivity) getActivity();
        g_App = (EFBGlobalData) getActivity().getApplicationContext();

        initView();

        return rootView;
    }

    private void initView(){

        //添加卡片按钮
        m_imgAddTaskCard = (ImageButton) rootView.findViewById(R.id.btn_img_add_taskcard);

        m_imgAddTaskCard.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {


                View view = getLayoutInflater().inflate(R.layout.popupwin_add_task_card, null);

                if (addFlyCardPopupWindow == null) {

                    addFlyCardPopupWindow = new AddFlyCardPopupWindow(activity,view,ViewGroup.MarginLayoutParams.MATCH_PARENT,
                            ViewGroup.MarginLayoutParams.MATCH_PARENT, 0, 0, true);
                } else {

                    addFlyCardPopupWindow.showAtLocation(activity.getWindow().getDecorView(),
                            Gravity.CENTER, 0, 0);
                }


            }
        });




    }
}